import {
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  JoinColumn,
  Entity,
} from 'typeorm';
import { User } from './User';

@Entity({ name: 'user_extend' })
export class UserExtend {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '主键id',
  })
  id: number;
  @Column({
    type: 'varchar',
    length: 11,
    nullable: true,
    name: 'mobile',
    comment: '手机号码',
  })
  mobile: string;
  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    name: 'address',
    comment: '地址',
  })
  address: string;
  //   使用@OneToOne 装饰器允许我们在2个实体之间创建一对一的关系
  // user => user.userDetail表示反向关系查询的
  @OneToOne(
    type => User,
    user => user.userDetail,
  )
  // @JoinColumn装饰器表示实体键的对应关系
  @JoinColumn()
  user: User; // 添加一个属性 user 去关联User表
}
